package com.tau.egonetwork.linkedin;

import com.tau.egonetwork.common.Configurations;
import com.tau.egonetwork.net.IRequest;

public class LinkedinAuthRequest {

	private final static String APP_ID = "779z4rcdvlb5ar";
	private final static String APP_SECRET = "fhuyiIoxKtgS9kKu";

	/* State for Linkedin to prevent CSRF : */
	public final static String STATE = "L8Src4DD";

	public final static String REDIRECT = Configurations.getLinkedinRedirectURL();
	
	public static IRequest generateAuthRequest() {
		return new IRequest() {
			
			@Override
			public String generateRequestURL() {

				StringBuilder s = new StringBuilder();
				
				s.append("https://www.linkedin.com/uas/oauth2/authorization");
				s.append("?response_type=code");
				s.append("&client_id=");
				s.append(APP_ID);
				s.append("&state=");
				s.append(STATE);
				s.append("&redirect_uri=");
				s.append(REDIRECT);

				s.append("&scope=");
				s.append("r_fullprofile");
				s.append("%20r_network");
				s.append("%20rw_groups");
				s.append("%20r_contactinfo");

				return s.toString();
			}
		};
	}
	
	public static IRequest generateAuthCodeRequest(final String code) {
		return new IRequest() {
			
			@Override
			public String generateRequestURL() {
				
				StringBuilder s = new StringBuilder();
				
				s.append("https://www.linkedin.com/uas/oauth2/accessToken");
				s.append("?grant_type=authorization_code");
				s.append("&code=");
				s.append(code);
				s.append("&redirect_uri=");
				s.append(REDIRECT);
				s.append("&client_id=");
				s.append(APP_ID);
				s.append("&client_secret=");
				s.append(APP_SECRET);
				
				return s.toString();
			}

		};
	}
}
